package com.gxa.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.dto.MyParam;
import com.gxa.dto.ResultDto;
import com.gxa.mapper.UserMapper;
import com.gxa.pojo.User;
import com.gxa.service.AdminService;
import com.gxa.util.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Service
public class AdminServiceImpl implements AdminService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public ResultDto showTable(MyParam myParam) {
        PageHelper.startPage(myParam.getPage(),myParam.getLimit());
        List<User> userList = userMapper.findAll();
        PageInfo<User> pageInfo = new PageInfo<>(userList);
        return Response.success(0,"success",Integer.valueOf(pageInfo.getTotal()+""),pageInfo.getList());
    }

    /**
     * 删除
     * @param userId
     * @return
     */
    @Override
    public ResultDto delete(Integer userId){
        userMapper.deleteByPrimaryKey(userId);
        return Response.success();
    };
}
